package com.voyage.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.voyage.common.constant.PageMO;
import com.voyage.system.entity.MenuDO;
import com.voyage.system.mapper.MenuRepository;
import com.voyage.system.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: voyage
 * @Date: 2021-10-24
 * @Description: MenuServiceImpl
 */
@Service
public class MenuServiceImpl implements MenuService {

    private final MenuRepository menuRepository;

    @Autowired
    public MenuServiceImpl(MenuRepository menuRepository) {
        this.menuRepository = menuRepository;
    }


    @Override
    public void insert(MenuDO menuDO) {
        menuRepository.insert(menuDO);
    }

    @Override
    public List<MenuDO> list(QueryWrapper<MenuDO> queryWrapper) {
        return menuRepository.selectList(queryWrapper);
    }

    @Override
    public void update(MenuDO menuDO) {
        menuRepository.updateById(menuDO);
    }

    @Override
    public void delete(Long id) {
        menuRepository.deleteById(id);
    }

    @Override
    public IPage<MenuDO> page(PageMO pageMO) {
        IPage<MenuDO> page = new Page<>(pageMO.getCurrent(), pageMO.getSize());
        QueryWrapper<MenuDO> queryWrapper = new QueryWrapper<>();
        return menuRepository.selectPage(page, queryWrapper);
    }
}
